<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <title>问题上报查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="queryInfo.factoryname+'问题上报查询报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="主制分厂:" prop="factoryid">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择主制分厂" clearable filterable @change="bindControl">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="提出单位:">
          <el-select v-model="queryInfo.createworkcenterid" placeholder="请选择提出单位" clearable filterable>
            <el-option v-for="w in workcenterList" :key="w.workcenterid" :label="w.workcentername"
              :value="w.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="提出人:">
          <el-select v-model="queryInfo.creater" placeholder="请选择提出人" clearable filterable>
            <el-option v-for="w in factoryUsers" :key="w.employeeid" :label="w.fullname" :value="w.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="提出时间:">
          <el-date-picker v-model="queryInfo.createdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="责任工区:">
          <el-select v-model="queryInfo.workcenterid" placeholder="请选择责任工区" clearable filterable>
            <el-option v-for="w in workcenterList" :key="w.workcenterid" :label="w.workcentername"
              :value="w.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="责任人:">
          <el-select v-model="queryInfo.responser" placeholder="请选择责任人" clearable filterable>
            <el-option v-for="w in factoryUsers" :key="w.employeeid" :label="w.fullname" :value="w.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="批次号:">
          <el-input v-model.trim="queryInfo.containername" placeholder="请输入批次号" clearable></el-input>
        </el-form-item>

        <el-form-item label="状态:">
          <el-select v-model="queryInfo.status" placeholder="请选择状态" clearable filterable>
            <el-option :key="'未处理'" :label="'未处理'" :value="'未处理'"></el-option>
            <el-option :key="'处理中'" :label="'处理中'" :value="'处理中'"></el-option>
            <el-option :key="'处理完'" :label="'处理完'" :value="'处理完'"></el-option>
            <el-option :key="'已关闭'" :label="'已关闭'" :value="'已关闭'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="问题描述" prop="description" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="问题详述" prop="notes" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="处理意见" prop="ufcresult" show-overflow-tooltip></el-table-column>
        <el-table-column label="问题类型" prop="ufccontent" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="责任人" prop="responsibleperson" width="80">
          <template slot-scope="scope" v-if="scope.row.responsibleperson">
            <el-tag>{{scope.row.responsibleperson}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="责任单位" prop="workcentername" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="提出人" prop="createperson" width="80">
          <template slot-scope="scope" v-if="scope.row.createperson">
            <el-tag>{{scope.row.createperson}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="提出单位" prop="createworkcenter" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="问题提出时间" prop="ufccreatedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="要求完成时间" prop="ufcchulidate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="问题完成时间" prop="ufcwanchengdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="问题关闭时间" prop="ufcguanbidate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="状态" prop="status" width="90">
          <template slot-scope="scope" v-if="scope.row.status">
            <el-tag v-if="scope.row.status === '已关闭'" type="info">{{scope.row.status}}</el-tag>
            <el-tag v-else-if="scope.row.status === '处理中'" type="warning">{{scope.row.status}}</el-tag>
            <el-tag v-else-if="scope.row.status === '处理完'" type="success">{{scope.row.status}}</el-tag>
            <el-tag v-else type="danger">{{scope.row.status}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="需求程度" prop="priority" width="100"></el-table-column>
        <el-table-column label="超期天数" prop="delayday" width="80"></el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[12,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { exportExcelData, getParams } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactoryInfo, getFactory, getFactoryUsers, getWorkcenterList } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        queryInfo: {
          factoryname: '',
          factoryid: '',
          createworkcenterid: '', // 提出单位
          workcenterid: '', // 责任单位
          containername: '',
          creater: '',// 提出人
          responser: '', // 责任人
          createdate: '',// 问题提出时间
          status: '',
          currentPage: 1,//当前页
          pageSize: 12//每页显示条数
        },
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        dataList: [],
        factoryList: [], // 分厂列表
        factoryUsers: [],
        workcenterList: [],
        // 表单验证
        rules: { factoryid: [{ required: true, message: '主制分厂不能为空', trigger: 'change' }] },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        async bindControl(factoryid) {
          this.queryInfo.createworkcenterid = null;
          this.queryInfo.workcenterid = null;
          this.queryInfo.creater = null;
          this.queryInfo.responser = null;
          if (factoryid) {
            this.workcenterList = await getWorkcenterList({ factoryid });
          }
        },
        //查询数据
        async getData(currentpage) {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios.post('../handler/report/ZSProblemReport.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
            }
          })
        },
        //导出excel
        async getExportExcel() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              const config = {
                url: '../handler/report/ZSProblemReport.ashx?action=exportExcel',
                data: {
                  type: 'exportExcel',
                  ...this.queryInfo,
                  factoryname: this.factoryname
                }
              }
              exportExcelData(config, this);
            }
          })
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        const factoryid = Decrypt(getParams('factoryid'));
        const factoryInfo = await getFactoryInfo({ factoryid, isMapping: '是' });
        const { factoryname } = factoryInfo[0];
        this.queryInfo.factoryname = factoryname;
        document.title = factoryname + '问题上报查询报表';
        this.factoryList = await getFactory();
        this.queryInfo.factoryid = this.factoryList.filter(i => i.factorycode === '603')[0].factoryid;
        this.workcenterList = await getWorkcenterList({ factoryid });
        this.factoryUsers = await getFactoryUsers({ factoryid });
      },
      watch: {
        queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true }
      }
    })
  </script>
</body>

</html>